package cn.stylefeng.guns.modular.pandian.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.pandian.entity.PandianJihua;
import cn.stylefeng.guns.modular.pandian.mapper.PandianJihuaMapper;
import cn.stylefeng.guns.modular.pandian.model.params.PandianJihuaParam;
import cn.stylefeng.guns.modular.pandian.model.result.PandianJihuaResult;
import  cn.stylefeng.guns.modular.pandian.service.PandianJihuaService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 盘点计划表 服务实现类
 */
@Service
public class PandianJihuaServiceImpl extends ServiceImpl<PandianJihuaMapper, PandianJihua> implements PandianJihuaService {

    @Override
    public void add(PandianJihuaParam param){
        PandianJihua entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(PandianJihuaParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(PandianJihuaParam param){
        PandianJihua oldEntity = getOldEntity(param);
        PandianJihua newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public PandianJihuaResult findBySpec(PandianJihuaParam param){
        return null;
    }

    @Override
    public List<PandianJihuaResult> findListBySpec(PandianJihuaParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(PandianJihuaParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(PandianJihuaParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private PandianJihua getOldEntity(PandianJihuaParam param) {
        return this.getById(getKey(param));
    }

    private PandianJihua getEntity(PandianJihuaParam param) {
        PandianJihua entity = new PandianJihua();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public LayuiPageInfo findPageBySpecApplets(PandianJihuaParam param, String condition,Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findPageBySpecApplets(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
	}

}
